home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-03-12 | 3.5 KB | 164 lines | [TEXT/CWIE] |
- /*
- ********************************************************************************
- **
- ** File: GSpTest_Main.cp
- **
- ** Description:
- **
- ** Contains the program entry point and some error handling routines.
- **
- ********************************************************************************
- */
- #include "GSpTest_Main.h"
- #include "GSpTest_Init.h"
- #include "GSpTest_EventLoop.h"
-
- #include "GoggleSprocket.h"
- #include "GoggleSprocketDevices.h"
-
- /*
- ********************************************************************************
- ** local constants
- ********************************************************************************
- */
- #define kErrorDialogItem_Button 1
- #define kErrorDialogItem_UserFrame 6
-
- #define kDLOG_ErrorID 128
-
- /*
- ********************************************************************************
- ** prototypes
- ********************************************************************************
- */
- static void DoTest( void );
-
- /*
- ********************************************************************************
- **
- ** Name: main
- **
- ** Description:
- **
- ** Program entry point.
- **
- ********************************************************************************
- */
- void main( void )
- {
- OSErr theError;
-
- // increase size of the app heap zone to its maximum
- MaxApplZone();
-
- // alloc the master pointers
- for (int i = 0; i < 5; i++)
- MoreMasters();
-
- // initialization
- theError = Initialize();
- if( theError )
- HandleError( theError, true );
-
- // Testing
- DoTest();
-
- // main loop
- EventLoop();
-
- // termination
- Terminate();
- }
-
- /*
- ********************************************************************************
- **
- ** Name: HandleError
- **
- ** Description:
- **
- ** Displays an error dialog and terminates the program if the error
- ** is fatal.
- **
- ********************************************************************************
- */
- void HandleError(
- short inTextID, // 'STR ' id of error text
- Boolean inFatal // true if error is fatal
- )
- {
- GrafPtr theOldPort;
- DialogPtr theDialog;
-
- theDialog = GetNewDialog( kDLOG_ErrorID, nil, (WindowPtr) -1);
- if (theDialog != nil)
- {
- Handle theItem;
- short theItemType;
- Rect theItemRect;
- StringHandle theString;
- short theItemHit;
-
- SysBeep( 30 );
- SetCursor( &qd.arrow );
-
- GetPort( &theOldPort );
- SetPort( theDialog );
-
- // frame user area
- PenPat( &qd.gray );
- GetDialogItem( theDialog, kErrorDialogItem_UserFrame, &theItemType, &theItem,
- &theItemRect );
- FrameRect( &theItemRect );
- PenPat( normal );
-
- // get the button item
- GetDialogItem( theDialog, kErrorDialogItem_Button, &theItemType, &theItem,
- &theItemRect );
- SetDialogDefaultItem( theDialog, kErrorDialogItem_Button );
-
- // display the error message
- theString = GetString( inTextID );
- if( NULL == theString )
- theString = GetString( kError_Unknown );
- HLock( (Handle)theString );
- ParamText( *theString, nil, nil, nil );
- HUnlock( (Handle)theString );
-
- // show the dialog
- ShowWindow( theDialog );
- ModalDialog( nil, &theItemHit );
-
- // restore things
- SetPort( theOldPort );
- DisposeWindow( theDialog );
- }
- else
- Terminate();
-
- // fatal?
- if ( inFatal )
- Terminate();
-
- }
-
- /*
- ********************************************************************************
- **
- ** Name: DoTest
- **
- ** Description:
- **
- ** Does GSp Testing.
- **
- ********************************************************************************
- */
- void DoTest( void )
- {
- OSStatus theError;
-
- // test device selection dialog
- theError = GSpConfigure( NULL, NULL );
- if( theError )
- return;
- }